package edu.neumont.pro180._2009_q2.network;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import edu.neumont.pro180._2009_q2.GamePieceMove;
import edu.neumont.pro180._2009_q2.Player;
import edu.neumont.pro180._2009_q2.interfaces.IGamePiece;

public class Opponent extends Player {
	@Override
	public GamePieceMove getNextMove() {

		// get the string representation of the move
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();

		// get the coordinates from the move, convert them to points
		Pattern pattern = Pattern.compile("\\w\\d");
		Matcher m = pattern.matcher(input);
		ArrayList<Point> points = new ArrayList<Point>();
		while (m.find()) {
			String pointString = m.group();
			Point p = NetworkGame.stringToPoint(pointString);
			points.add(p);
		}

		// create all the moves that need to be made
		List<GamePieceMove> moves = new ArrayList<GamePieceMove>();
		for (int i = 0; i < points.size(); i += 2) {
			IGamePiece piece = this.board.getSquare(points.get(i))
					.getGamePiece();
			GamePieceMove move = piece.getMove(this.board.getSquare(points.get(i + 1)));
			moves.add(move);
		}
		return new ComplexMove(moves);
	}
}
